package com.example.myapplication

import android.os.Bundle
import android.view.ViewGroup
import android.widget.Button
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import android.widget.LinearLayout
import android.widget.TextView
import java.util.Locale

class MyActivity :AppCompatActivity(){
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val linearLayout=LinearLayout(this)
        linearLayout.orientation=LinearLayout.VERTICAL
        val textView=TextView(this)
        textView.layoutParams=ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT)
        textView.textSize=30F
        textView.text=getString(R.string.textView)
        linearLayout.addView(textView)
        val button=Button(this)
        button.width=ViewGroup.LayoutParams.MATCH_PARENT
        button.height=ViewGroup.LayoutParams.WRAP_CONTENT
        button.text=getString(R.string.button)
        linearLayout.addView(button)
        val imageView = ImageView(this)
        imageView.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
        if (Locale.getDefault().language == Locale.ENGLISH.language) {
            imageView.setImageResource(R.drawable.usa_flag)
        }
        else if (Locale.getDefault().language == Locale.JAPANESE.language) {
            imageView.setImageResource(R.drawable.japan_flag)
        }
        else {
            imageView.setImageResource(R.drawable.china_flag)
        }
        linearLayout.addView(imageView)
        setContentView(linearLayout)
        button.setOnClickListener {
            textView.text = getString(R.string.clicked)
        }
        setContentView(linearLayout)
        button.setOnClickListener(){
            textView.text=getString(R.string.clicked)
        }


    }
}